import { ChangeDetectorRef, Component } from '@angular/core';
import { GreenworksService } from '../../service/greenworks.service';

@Component({
  selector: 'app-steam',
  templateUrl: './steam.component.html',
  styleUrls: ['./steam.component.scss'],
})
export class SteamComponent {
  title = 'demo-steam2';
  status1 = 'wait';
  status2 = 'wait';
  status3 = 'wait';
  status4: any = 'wait';
  status5 = 'wait';
  status6 = 'wait';
  error: any;


  constructor(
      private greenworks: GreenworksService,
      private cdf: ChangeDetectorRef,
  ) {
  }

  activateAchievement() {
    try {
      this.greenworks.activateAchievement('ACH_WIN_100_GAMES').subscribe({
        next: () => {
          this.status2 = 'done';
          this.cdf.detectChanges();
        }, error: (e: any) => {
          this.status2 = e;
        },
      });
    } catch (e) {
      this.error = e;
    }
  }

  test3() {
    this.greenworks.clearAchievement('ACH_WIN_100_GAMES').subscribe({
      next: () => {
        this.status3 = 'done';
        this.cdf.detectChanges();
      }, error: (e: any) => {
        this.status5 = e;
      },
    });
  }

  test4() {
    try {
      this.status4 = this.greenworks.getAchievementNames();
    } catch (e) {
      this.error = e;
    }
  }

  testAuth() {
    this.status5 = 'waiting';
    try {
      this.greenworks.testAuth();
    } catch (e) {
      console.log('e', e);
    }
  }

  test() {
    this.greenworks.test();
    // let friendFlag = this.greenworks.greenworks.FriendFlags.Immediate;
    // console.log('friendFlag', friendFlag);
    // console.log('friendFlag', this.greenworks.greenworks);
    // let result = JSON.stringify(this.greenworks.greenworks, (k: any, v: any) => {
    //   if (typeof v === 'function') {
    //     return 'function';
    //   }
    //   return v;
    // });
    // console.log('friendFlag', result);
    // let result = this.greenworks.greenworks.getFriendsAccount(friendFlag);
    // let result = this.greenworks.greenworks.ClearRichPresence();
    // console.log('test result', result)
  }
}
